package com.esteel.settlement.service.impl;

import java.util.concurrent.ExecutorService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.esteel.settlement.dao.SettPacketLogRepository;
import com.esteel.settlement.entity.TbSettPacketLog;
import com.esteel.settlement.pa.packet.PaPacket;
import com.esteel.settlement.service.SettPacketLogService;

@Service
public class SettPacketLogServiceImpl implements SettPacketLogService{

	@Autowired
	private SettPacketLogRepository settPacketLogRepository;
	
	@Autowired
	private ExecutorService threadPool;

	@Override
	public void add(final PaPacket packet) {
	
		//采用异步存储的方式解决处理过程中的效率问题
		
		Runnable worker = new Runnable(){

			@Override
			public void run() {
				TbSettPacketLog log = new TbSettPacketLog();
				log.setLogNo(packet.getThirdLogNo());
				log.setRspCode(packet.getRspCode());
				log.setPacket(packet.marshal());
				log.setTranDate(packet.getTransDate());
				log.setTranFunc(packet.getTranFunc());
				settPacketLogRepository.save(log);
			}
			
		};
		
		threadPool.execute(worker);
	}

	@Override
	public void add(TbSettPacketLog tbSettPacketLog) {
		settPacketLogRepository.save(tbSettPacketLog);
	}
	


}
